import cv2 as cv
import numpy as np


def random_pixel(pix):
    if pix > 255:
        return 255
    if pix < 0:
        return 0
    else:
        return pix


def gaussian_noise(img):
    h, w, ch = img.shape
    for row in range(h):
        for col in range(w):
            b = img[row,col,0]
            g = img[row,col,1]
            r = img[row,col,2]
            s = np.random.normal(0,20,3)

            img[row, col, 0] = random_pixel(b + s[0])
            img[row, col, 1] = random_pixel(g + s[1])
            img[row, col, 2] = random_pixel(r + s[2])


def gaussian_demo(img):
    dst = cv.GaussianBlur(img,(0,0),15)
    cv.imshow('median-blur',dst)


src = cv.imread('lena.jpg', 1)
cv.namedWindow('demo',cv.WINDOW_AUTOSIZE)
cv.imshow('demo', src)
# gaussian_noise(src)
# cv.imshow('gaussian_noise',src)
gaussian_demo(src)
cv.waitKey(0)
cv.destroyWindow('demo')